﻿using Server.MessageModule.Message;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Server.MessageModule.MessageProcessor
{
    class CommandProcessor : BaseMessageProcessor
    {
        public CommandProcessor()
            : base(ShareMacro.MESSAGETYPE_COMMAND)
        {
        }

        public override void onReceiptMessage(INetworkMessage msg)
        {
            SensorProcessor sensor = _msgDispatcher.getProcessor(ShareMacro.MESSAGETYPE_SENSOR) as SensorProcessor;

            string msgType = msg.getType();
            if (msgType != ShareMacro.MESSAGETYPE_COMMAND)
                return;

            CommandMessage cmd = msg as CommandMessage;
            if (cmd == null)
                throw new Exception("Invalid type message");

            string command = cmd.Command;
            switch (command)
            {
                case ShareMacro.COMMAND_SENDMESSAGE:
                    string message = cmd.getParam(ShareMacro.COMMAND_MESSAGEDATA) as string;
                    doPrintMessage(message);
                    break;
                case ShareMacro.COMMAND_CAPTUREORIENTATION:
                    if (sensor != null)
                        sensor.setCaptureMode(true);
                    else
                        Console.WriteLine("Error: Command processor - sensor null");
                    break;
                case ShareMacro.COMMAND_FILTERMODE:
                    if (sensor != null)
                        sensor.setFilterMode(true);
                    else
                        Console.WriteLine("Error: Command processor - sensor null");
                    break;
                default:
                    break;
            }
        }

        private void doPrintMessage(String message)
        {
            System.Console.WriteLine(message);
        }
    }
}
